package com.atguigu.tingshu.order.listener;

import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.common.constant.SystemConstant;
import com.atguigu.tingshu.order.service.OrderInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

/**
 * title:
 * author: zgl
 * date: 2024/3/18
 * description：
 */
@Component
public class OrderListener {
    @Autowired
    private OrderInfoService orderInfoService;

    @KafkaListener(topics = KafkaConstant.QUEUE_ORDER_PAY_SUCCESS)
    public void paySuccess(String orderNo, Acknowledgment ack) {
        if (StringUtils.isBlank(orderNo)) {
            ack.acknowledge();
            return;
        }
        this.orderInfoService.updateOrderStatus(orderNo, SystemConstant.ORDER_STATUS_UNPAID,SystemConstant.ORDER_STATUS_PAID);
        ack.acknowledge();
    }
}
